﻿<%@ Page Language="C#" MasterPageFile="~/AJAXMaster.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="Gridview">  
  <asp:GridView EnableViewState="false" runat="server" id="_grid" OnRowDataBound="_grid_RowDataBound">  
   </asp:GridView>  
   <span id ="ServerMsg"></span>  
   </div>  
   <input type=button value="Update" onclick="javascript: JSUpdateTable();" />  
   <script language="javascript">  
       function UpdateGrid(args)  
       {  
            <%= ClientScript.GetCallbackEventReference(this,"args", "ShowResult", null) %>;  
       }  
       function MakeCellEditable(obj)  
       {
           if(!window.document.getElementById(obj.id + "_input"))   
           {
               obj.innerHTML = "<input id="+ obj.id + "_input" + " type=text value='" + obj.innerText + "'/>"
           }
   
           window.document.getElementById(obj.id + "_input").focus();  
       }
       
       function JSUpdateTable()
       {
            var ddl = window.document.getElementById('Gridview');  
            var ddl1 = ddl.getElementsByTagName('input');  
            var data = "";  
            for(i = 0 ; i < ddl1.length ; i++)  
            {   
                ddlId[i] = ddl1[i].id; //ddlId is a global array in JS we will use it in step 9  
                if(i == 0 ) data = ddl1[i].id + "|" +  ddl1[i].value;   
                else data = data + "~" + ddl1[i].id + "|" +  ddl1[i].value;  
            }  
            UpdateGrid('updateTable$'+data);  
       }
       
       function UpdateGrid(args)  
       {  
           <%= ClientScript.GetCallbackEventReference(this,"args", "ShowResult", null) %>;  
       }  
       var ddlId = new Array();//Elements are added in step 7  
       // This array contain ids of textboxes  
       function ShowResult(eventArgument ,context)  
       {
        formObj = window.document;  
       if(eventArgument == "SUCCESS")   
           {  
              for(j = 0 ; j < ddlId.length ; j++)  
               {  
                    var ids = ddlId[j].split("_");  
                    formObj.getElementById(ids[0] + "_" + ids[1]).innerHTML = formObj.getElementById(ddlId[j]).value;  
               }  
              document.getElementById('ServerMsg').innerText = "Data has been updated Successfully...";  
           } 
       }
  </script>  
</asp:Content>

